<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui" >

    <!-- INTERFACE -->
    <cc:interface>
        <cc:attribute name="var" type="java.lang.Object" required="true" />
        <cc:attribute name="bean" type="java.lang.Object" required="true"  />    
        <cc:attribute name="property" type="java.lang.String" required="true" />
        <cc:attribute name="editable" type="java.lang.Boolean" default="false" />
        <cc:attribute name="deleteMethod" type="java.lang.String" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <div class="#{cc.attrs.var.destacada ? 'itemDestacado':'item'}" >
            <h:panelGrid columns="3" style="border: none;"
                         cellspacing="0" cellpadding="0" 
                         columnClasses="itemImgCol,itemContentCol,itemPriceCol" > 
                <h:graphicImage value="/image?id=#{cc.attrs.var.imagenId}"
                                width="113" height="85" styleClass="imagenPublicacion"
                                rendered="#{cc.attrs.var.imagenId != -1}" />
                <h:graphicImage value="#{resource['images:noImage.png']}" 
                                width="#{cc.attrs.var.destacada ? '140':'113'}" 
                                height="#{cc.attrs.var.destacada ? '105':'85'}" styleClass="imagenPublicacion"
                                rendered="#{cc.attrs.var.imagenId == -1}" />
                <h:panelGrid styleClass="gridCentro" style="padding: 0 10px;text-align: left; font-family: Ubuntu;" 
                             columns="1"   >
                    <h:link value="#{cc.attrs.var.titulo}"
                                   outcome="/vistas/mostrarPublicacion" 
                                   styleClass="#{cc.attrs.var.destacada ? 'itemTitleDestacado':'itemTitle'}" >
                        <f:param name="id" value="#{cc.attrs.var.id}" />
                    </h:link>

                    <h:panelGrid columns="#{cc.attrs.var.destacada ? 2: 3}" rowClasses="editColumn" style="width:50%" >
                        <h:link value="editar" rendered="#{cc.attrs.editable}"
                                       outcome="/vistas/usuario/modificarPublicacion" >
                            <f:param name="id" value="#{cc.attrs.var.id}" />
                        </h:link>
                        <h:link value="destacar" rendered="#{cc.attrs.editable and not cc.attrs.var.destacada}"
                                       outcome="/vistas/usuario/destacarPublicacion" >
                            <f:param name="id" value="#{cc.attrs.var.id}" />
                        </h:link>
                        <p:commandLink value="eliminar" rendered="#{cc.attrs.editable}"
                                       onclick="confirmarDlg.show()" >
                            <f:setPropertyActionListener value="#{cc.attrs.var.id}" target="#{cc.attrs.bean[cc.attrs.property]}" />
                        </p:commandLink>
                    </h:panelGrid>

                    <h:outputText value="(#{cc.attrs.var.ciudad}, #{cc.attrs.var.provincia})" />
                    
                </h:panelGrid>
                <h:dataTable value="#{cc.attrs.var.precios}" columnClasses="precioColDesc,precioColValor"
                             var="precio" style="text-align: left">
                    <h:column >
                        <h:outputText value="#{precio.periodoNombre}:" />  
                    </h:column>        
                    <h:column>
                        <h:outputText value=" $ #{precio.precio}" />  
                    </h:column>
                </h:dataTable>
            </h:panelGrid>
        </div>

        <p:dialog widgetVar="confirmarDlg" header="Eliminar publicacion" modal="true" resizable="false" style="text-align: center;" >
            <p>
                Esta seguro que desea eliminar esta publicacion?
            </p>
            <br/>
            <f:facet name="footer" >
                <p:commandButton value="Aceptar" action="#{cc.attrs.bean[cc.attrs.deleteMethod]}"
                                 oncomplete="confirmarDlg.hide()" ajax="false" >    
                </p:commandButton>
                <p:commandButton value="Cancelar" onclick="confirmarDlg.hide()" />
            </f:facet>
            
            
        </p:dialog>
    </cc:implementation>
</html>
